<?php

class Scan
{
	const PHOTO_PATH = 'photos';

	public static function scanFolders()
	{
		$categories = Categories::getAllCategories();
		foreach($categories as $num=>$cat){
			$instance = Yii::app()->file->set(self::PHOTO_PATH.DIRECTORY_SEPARATOR.$cat, true);
			$files = $instance->getContents();

			$ini_name = self::PHOTO_PATH.DIRECTORY_SEPARATOR.$cat.DIRECTORY_SEPARATOR.'images.ini';
			if(file_exists($ini_name))
				unlink($ini_name);

			$counter = 1;
			foreach($files as $file) {
				if(basename($file) != 'images.ini') {
					$result[] = basename($file);
					file_put_contents($ini_name,'image['.$counter.'] = '.basename($file).PHP_EOL,FILE_APPEND);
					$counter ++;
				}
			}
		}
	}
}